//------------------------------------------------------------------------------------------------
// The MIT License (MIT)
// 
// Copyright (c) 2019 Crsky
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//------------------------------------------------------------------------------------------------

#ifndef CONVAR_H
#define CONVAR_H

//------------------------------------------------------------------------------------------------
// Console variable flags
//------------------------------------------------------------------------------------------------
constexpr int CONVAR_ARCHIVE	= 1<<0;	// Auto save to file
constexpr int CONVAR_ENGINE		= 1<<1;	// Defined in engine module
constexpr int CONVAR_CLIENT		= 1<<2;	// Defined in client module
constexpr int CONVAR_SERVER		= 1<<3;	// Defined in server module

//------------------------------------------------------------------------------------------------
// String based console variable
//------------------------------------------------------------------------------------------------
class ConVar
{
public:
	ConVar() = delete;
	ConVar( const ConVar& ) = delete;
	ConVar& operator=( const ConVar& ) = delete;
	~ConVar();

public:
	explicit ConVar( const char* name, const char* default_value = "", int flags = 0, const wchar_t* help_string = L"" );
	explicit ConVar( const char* name, int default_value = 0, int flags = 0, const wchar_t* help_string = L"" );
	explicit ConVar( const char* name, double default_value = 0, int flags = 0, const wchar_t* help_string = L"" );

	// Getter
	virtual const char* GetValueString() const;
	virtual int			GetValueInt() const;
	virtual double		GetValueDouble() const;

	// Setter
	virtual void SetValueString( const char* value );
	virtual void SetValueInt( int value );
	virtual void SetValueDouble( double value );

	// Reset to default value
	virtual void Reset();

	// Details
	virtual const char* GetName() const;
	virtual const char* GetDefaultValue() const;
	virtual const char* GetHelpString() const;

	// If the variable sets a new value, this function returns true
	// use for variable change notify callback
	virtual bool IsValueChanged() const;
	virtual void MarkChanged();

private:
	// Cvar name
	string name_;

	// Help string
	wstring help_string_;

	// Default value
	string default_value_;

	// Current value
	string current_value_;

	// Converted from the string value
	int current_value_int_;
	double current_value_double_;
};

#endif
